// component/coupon-list.js
const config = require('../../config.js');
const request = require('../../utils/request.js')
const utils = require('../../utils/util.js');

import {    
    getAppointTime
} from '../../static/api/api.js'
let app = new getApp()
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        searchParams: Object,
        isShow: Boolean,
    },
    data: {
        curDate: null,
        curDateTime: null
    },
    attached: function() {
        let that = this;
        console.log(this.data.searchParams)
        this.data.searchParams.set_date = '';
        this.data.searchParams.type = 1;
        this.getAppointTime(this.data.searchParams)
        setTimeout(function() {
            that.setData({
                iscShow: true
            })
        })
    },
    /**
     * 组件的初始数据
     */
    data: {
        couponList: null
    },
    /**
     * 组件的方法列表
     */
    methods: {
        _hideDialog(e) {
            console.log(e)
            let dataset = e.currentTarget.dataset;
            if (dataset.type == "1") {
                this.triggerEvent('closePop', {
                    type: 1
                });
            } else {
                this.triggerEvent('closePop', {
                    type: dataset.type,
                    item: dataset.item
                });
            }

        },
        //获预约时间信息
        getAppointTime(options) {
            let that = this
            this.setData({
                pageLoad:true
            })
            getAppointTime(options).then((response) => {
                this.setData({
                    pageLoad: false
                })
                that.setData({
                    'dateList': response.data.dateList,
                    'time_data': response.data.time_data
                })
                console.log(options)
                if (options.type == 1) {
                    that.setData({
                        'curDate': response.data.dateList[0]
                    })
                }

            }).catch((response) => {
                this.setData({
                    pageLoad: false
                })
            })
        },
        dateNavChange(e) {
            let dataset = e.currentTarget.dataset;
            this.getAppointTime({
                store_user_id: this.data.searchParams.store_user_id,
                set_date: dataset.set_date,
                type:2
            })
            this.setData({
                'curDate': dataset.item,
                'time_data':null
            })

        },
        chooseApTime(e){
            let dataset = e.currentTarget.dataset;
            if(dataset.item == 0 || dataset.item == 4){
                return;
            }
            this.setData({
                'curDateTime': this.data.curDate.date+' '+dataset.index+':00'
            })
        },
        comfirmChooseData() {
            if (!this.data.curDateTime){
                wx.showToast({
                    icon:'',
                    title: '请选择预约时间',
                })
            }
            this.triggerEvent('comfirm', {
                date: this.data.curDateTime
            });
        }
    },
    

})